﻿//21.Write a program that reads a string from the console and prints all different letters in the string along with information how many times each letter is found. 

using System;
using System.Collections.Generic;

namespace DifferentLetters
{
    class DifferentLetters
    {
        static void Main()
        {
            Console.Write("Enter text: ");
            string text = Console.ReadLine();

            List<char> lettersList = new List<char>();
            List<int> occurencesList = new List<int>();
            int letterIndex = -1;

            for (int i = 0; i < text.Length; i++)
            {
                char currentChar = text[i];

                if (char.IsLetter(currentChar))
                {
                    if (CharExistIn(lettersList, currentChar, ref letterIndex))
                    {
                        occurencesList[letterIndex]++;
                    }
                    else
                    {
                        lettersList.Add(currentChar);
                        occurencesList.Add(1);
                    }
                }
            }

            for (int i = 0; i < lettersList.Count; i++)
            {
                Console.WriteLine("{0} --> {1}", lettersList[i], occurencesList[i]);
            }
        }

        private static bool CharExistIn(List<char> lettersList, char currentChar, ref int letterIndex)
        {
            bool hasFound = false;

            for (int i = 0; i < lettersList.Count; i++)
            {
                if (currentChar == lettersList[i])
                {
                    letterIndex = i;
                    hasFound = true;
                    break;
                }
            }
            return hasFound;
        }
    }
}
